package com.monkey.core.domain.auth;

import com.monkey.core.domain.permission.Permission;
import com.monkey.core.domain.resource.Menu;
import com.monkey.core.domain.role.RoleResourcePermission;
import com.monkey.core.domain.user.User;
import com.monkey.core.repository.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by silentwu on 2015/8/4.
 */
public interface UserResourcePermissionRepository extends BaseRepository<UserResourcePermission, Long> {

    @Query("from UserResourcePermission u where u.user.id = ?1")
    List<UserResourcePermission> findByUserId(Long userId);

    void deleteByUserAndMenuAndPermission(User user, Menu menu, Permission permission);

    List<UserResourcePermission> findByUserAndMenu(User user, Menu menu);

    Page<UserResourcePermission> findByUser(User user, Pageable pageable);
}
